import router from "@/router";
import { toast,Dialog } from "vant";
import {
  accounts,
  recharge,
  petOrders,
  inviteContent,
  verificationCodes,
  password,
  cards,
  bindcards,
  customers,
  banks,
  withdrawal,
  complaints,
  getComplaints,
  queryComplaints,
  replies,
  postReplies,
  photoc,
  orders,
  uploadDoc,
  docShow,
  friends,
  sendfriends,
  dianfriends,
  delfriends,
  sellout,
  problems,
  problemsrepy,
  channels,
  configurations,
  withdrawalCancel,
  statisticslixi,
  revenueslixibao,
  logs,
  rechargelixibao,
  withdrawallixibao,
  cancelPet
} from "@/server/my";
import { setStorage, setSession, removeStorage } from "@/utils/common";
export default {
  state: () => ({
    banks: [],
  }),
  mutations: {
    setbanks(state, data) {
      state.banks = data;
    },
  },
  actions: {
    accounts({ commit }, data) {
      return new Promise((resolve, reject) => {
        accounts(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    photoc({ commit }, data) {
      return new Promise((resolve, reject) => {
        photoc(data).then((res) => {
          if (res.code == 0) {
            toast("Modification succeeded");
            resolve(true);
          } else {
            toast(res.msg);
            resolve(false);
          }
        });
      });
    },
    recharge({ commit }, data) {
      return new Promise((resolve, reject) => {
        recharge(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else {
            toast(res.msg);
            resolve(false);
          }
        });
      });
    },
    petOrders({ commit }, data) {
      return new Promise((resolve, reject) => {
        petOrders(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    inviteContent({ commit }, data) {
      return new Promise((resolve, reject) => {
        inviteContent(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    verificationCodes({ commit }, data) {
      return new Promise((resolve, reject) => {
        verificationCodes(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    password({ commit }, data) {
      return new Promise((resolve, reject) => {
        password(data).then((res) => {
          
            resolve(res);
  
        });
      });
    },
    bindcards({ commit }, data) {
      return new Promise((resolve, reject) => {
        bindcards(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    cards({ commit }, data) {
      return new Promise((resolve, reject) => {
        cards(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    banks({ commit }, data) {
      return new Promise((resolve, reject) => {
        banks(data).then((res) => {
          if (res.code == 0) {
            commit("setbanks", res.data);
            let result = res.data.map((item) => item.name);
            resolve(result);
          }
        });
      });
    },
    withdrawal({ commit }, data) {
      return new Promise((resolve, reject) => {
        withdrawal(data).then((res) => {
          resolve(res);
        });
      });
    },
    customers({ commit }, data) {
      return new Promise((resolve, reject) => {
        customers(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    complaints({ commit }, data) {
      return new Promise((resolve, reject) => {
        complaints(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    getComplaints({ commit }, data) {
      return new Promise((resolve, reject) => {
        getComplaints(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    queryComplaints({ commit }, data) {
      return new Promise((resolve, reject) => {
        queryComplaints(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    replies({ commit }, data) {
      return new Promise((resolve, reject) => {
        replies(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    postReplies({ commit }, data) {
      return new Promise((resolve, reject) => {
        postReplies(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    orders({ commit }, data) {
      return new Promise((resolve, reject) => {
        orders(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    uploadDoc({ commit }, data) {
      return new Promise((resolve, reject) => {
        uploadDoc(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    docShow({ commit }, data) {
      return new Promise((resolve, reject) => {
        docShow(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          } else {
            toast(res.msg);
          }
        });
      });
    },
    friends({ commit }, data) {
      return new Promise((resolve, reject) => {
        friends(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    sendfriends({ commit }, data) {
      return new Promise((resolve, reject) => {
        sendfriends(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg);
          }
        });
      });
    },
    delfriends({ commit }, data) {
      return new Promise((resolve, reject) => {
        delfriends(data).then((res) => {
          if (res.code == 0) {
            resolve(true);
          }else{
            toast(res.msg)
            resolve(false)
          }
        });
      });
    },  
    dianfriends({ commit }, data) {
      return new Promise((resolve, reject) => {
        dianfriends(data).then((res) => {
            resolve(res);
        });
      });
    },
    sellout({ commit }, {pet_order_id,nextPetId}) {
      return new Promise((resolve, reject) => {
        sellout({pet_order_id}).then((res) => {
            if(res.code==0){
              toast("Sell out successfully!")
              resolve()
            }else if(res.code==80005){
                Dialog.confirm({
                  title: "Tips",
                  message: res.msg,
                  confirmButtonText: "To buy",
                  cancelButtonText: "Cancel",
                }).then(() => {
                router.push(`/marketdetail/${nextPetId}`);
              })              
            } else{
              toast(res.msg)
            }
        });
      });
    },
    problems({ commit }, data) {
      return new Promise((resolve, reject) => {
        problems(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    },  
    problemsrepy({ commit }, data) {
      return new Promise((resolve, reject) => {
        problemsrepy(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    },   
    channels({ commit }, data) {
      return new Promise((resolve, reject) => {
        channels(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    },   
    configurations({ commit }, data) {
      return new Promise((resolve, reject) => {
        configurations(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    },   
    withdrawalCancel({ commit }, data) {
      return new Promise((resolve, reject) => {
        withdrawalCancel(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    }, 
    statisticslixi({ commit }, data) {
      return new Promise((resolve, reject) => {
        statisticslixi(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    }, 
    revenueslixibao({ commit }, data) {
      return new Promise((resolve, reject) => {
        revenueslixibao(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    }, 
    logs({ commit }, data) {
      return new Promise((resolve, reject) => {
        logs(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }else{
            toast(res.msg)
          }
        });
      });
    }, 
    rechargelixibao({ commit }, data) {
      return new Promise((resolve, reject) => {
        rechargelixibao(data).then((res) => {
          if (res.code == 0) {
            toast("Successfully transferred");
            router.replace("/YuEBAO");
          }else{
            toast(res.msg)
          }
        });
      });
    },  
    withdrawallixibao({ commit }, data) {
      return new Promise((resolve, reject) => {
        withdrawallixibao(data).then((res) => {
          if (res.code == 0) {
            toast("Successfully transferred out");
            router.replace("/YuEBAO");
          }else{
            toast(res.msg)
          }
        });
      });
    }, 
    cancelPet({ commit }, data) {
      return new Promise((resolve, reject) => {
        cancelPet(data).then((res) => {
          if (res.code == 0) {
            resolve(res);
          }else{
            toast(res.msg)
          }
        });
      });
    }, 

    
    
  },
  getters: {},
};
